package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"log"
)

func main() {

	var b *bytes.Buffer

	b = bytes.NewBuffer([]byte("compact"))
	//compact 第二个参数貌似必须是json字符串的 []byte类型才行
	//err := json.Compact(b, []byte("{\"name\":\"joe\",\"age\":20,\"hobby\":[\"Basketball\",\"Football\",\"Reading\"]}"))
	err := json.Compact(b, []byte(`{"name":"joe","age":20,"hobby":["Basketball","Football","Reading"]}`))
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%v", b)
}
